﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CL.Business.BLL;
using CL.Business.Entity;
using CL.Enum.Common;
using CL.Enum.Common.Lottery;
using CL.Tools.Common;
using CL.View.Entity.Business;
using CL.View.Entity.Union;

namespace CL.UnionWeb.union
{
    public partial class MyBrokerage : BasePage
    {
        protected string currentYear;
        public const int years = 2;  //默认可查看2年内的预计分成
        protected List<Union_MyBrokerageViewModel> listItem;
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "推广联盟-我的佣金";
            currentYear = QPRequest.GetQueryString("currentYear");
            if (string.IsNullOrEmpty(currentYear))
                currentYear = DateTime.Now.ToString("yyyy");

            var Entity = base.GetUnionInfo();
            SettleMonthBLL bll = new SettleMonthBLL();
            var Entitys = bll.Querydivided(Entity.AccountID, currentYear);

            listItem = new List<Union_MyBrokerageViewModel>();
            foreach (var item in Entitys)
            {
                Union_MyBrokerageViewModel tmpItem = new Union_MyBrokerageViewModel();
                tmpItem.Month = item.Month;
                tmpItem.BuyMount = Math.Round((double)item.BuyMount / 100, 2);
                tmpItem.RebateNum = item.RebateNum;
                tmpItem.SettleStatus = item.SettleStatus == 0 ? "未结算" : item.SettleStatus == 1 ? "已结算" : item.SettleStatus == 2 ? "已审核" : item.SettleStatus == 3 ? "已发放":"";
                tmpItem.SettleAmount = Math.Round(tmpItem.BuyMount * tmpItem.RebateNum / 10000, 2);
                listItem.Add(tmpItem);
            }

            List<string> listYearMonth = new List<string>();
            for (int i = years; i > 0; --i)
            {
                listYearMonth.Add(DateTime.Now.AddYears(i - years).ToString("yyyy"));
            }
            yearMonth.DataSource = listYearMonth;
            yearMonth.DataBind();


            new RecordBLL().InsertEntity(new Business.Entity.RecordEntity()
            {
                AccountID = Entity.AccountID,
                RecordTime = DateTime.Now,
                RecordRemark = string.Format("查看 {0} 年费 结算中心 ", currentYear),
                RecordType = 6
            });

        }
    }
}